package org.jeecg.modules.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecg.common.api.vo.Result;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.entity.DiyTableStatus;
import org.jeecg.modules.service.IDiyTableStatusService;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 信息处理状态
 * @Author: Zhang Haoyu
 * @Date:   2020-05-25
 * @Version: V1.0
 */
@Api(tags="信息处理状态")
@RestController
@RequestMapping("/org/diyTableStatus")
@Slf4j
public class DiyTableStatusController extends JeecgController<DiyTableStatus, IDiyTableStatusService> {
	@Autowired
	private IDiyTableStatusService diyTableStatusService;


	 /**
	  * 重写分页方法  Zhang Haoyu
	  * @param diyTableStatus
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	@AutoLog(value = "信息处理状态-分页列表查询")
	@ApiOperation(value="信息处理状态-分页列表查询", notes="信息处理状态-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(DiyTableStatus diyTableStatus,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		Result<Page<DiyTableStatus>> result = new Result<>();
		Page<DiyTableStatus> page = new Page<>(pageNo, pageSize);
		page = diyTableStatusService.queryPage(page,diyTableStatus);//通知公告消息
		log.info("查询当前页：" + page.getCurrent());
		log.info("查询当前页数量：" + page.getSize());
		log.info("查询结果数量：" + page.getRecords().size());
		log.info("数据总数：" + page.getTotal());
		result.setSuccess(true);
		result.setResult(page);
		return result;
	}

	 /**
	  * 管理员审核功能  Zhang Haoyu
	  * @param professorTableId
	  * @param check
	  * @return
	  */
	 @AutoLog(value = "信息处理状态-通过审核")
	 @ApiOperation(value="信息处理状态-通过审核", notes="信息处理状态-通过审核")
	 @PostMapping(value = "/checker")
	 public Result<?> checker(String professorTableId,boolean check) {
		 System.out.println("审核id："+professorTableId);

		 // 调用业务层
		 boolean b = diyTableStatusService.check(professorTableId,check);
		 if(b){
			 // 发短信的方法
			 System.out.println("进入发短信的方法");
			 return Result.ok("审核通过！");

		 }
		 // 发短信的方法
		 System.out.println("进入发短信的方法");
		 return Result.error("审核失败！");


	 }



	/**
	 *   添加
	 *
	 * @param diyTableStatus
	 * @return
	 */
	@AutoLog(value = "信息处理状态-添加")
	@ApiOperation(value="信息处理状态-添加", notes="信息处理状态-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody DiyTableStatus diyTableStatus) {
		diyTableStatusService.save(diyTableStatus);
		return Result.ok("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param diyTableStatus
	 * @return
	 */
	@AutoLog(value = "信息处理状态-编辑")
	@ApiOperation(value="信息处理状态-编辑", notes="信息处理状态-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody DiyTableStatus diyTableStatus) {
		diyTableStatusService.updateById(diyTableStatus);
		return Result.ok("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "信息处理状态-通过id删除")
	@ApiOperation(value="信息处理状态-通过id删除", notes="信息处理状态-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		diyTableStatusService.removeById(id);
		return Result.ok("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "信息处理状态-批量删除")
	@ApiOperation(value="信息处理状态-批量删除", notes="信息处理状态-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.diyTableStatusService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.ok("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "信息处理状态-通过id查询")
	@ApiOperation(value="信息处理状态-通过id查询", notes="信息处理状态-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		DiyTableStatus diyTableStatus = diyTableStatusService.getById(id);
		if(diyTableStatus==null) {
			return Result.error("未找到对应数据");
		}
		return Result.ok(diyTableStatus);
	}






    /**
    * 导出excel
    *
    * @param request
    * @param diyTableStatus
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, DiyTableStatus diyTableStatus) {
        return super.exportXls(request, diyTableStatus, DiyTableStatus.class, "信息处理状态");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, DiyTableStatus.class);
    }

}
